.TH std::function::operator= 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::function::operator= \- std::function::operator=

.SH Synopsis
   function& operator=( const function& other );                \fB(1)\fP \fI(since C++11)\fP
   function& operator=( function&& other );                     \fB(2)\fP \fI(since C++11)\fP
   function& operator=( std::nullptr_t ) noexcept;              \fB(3)\fP \fI(since C++11)\fP
   template< class F >                                          \fB(4)\fP \fI(since C++11)\fP
   function& operator=( F&& f );
   template< class F >                                          \fB(5)\fP \fI(since C++11)\fP
   function& operator=( std::reference_wrapper<F> f ) noexcept;

   Assigns a new target to std::function.

   1) Assigns a copy of target of other, as if by executing
   function(other).swap(*this);
   2) Moves the target of other to *this. other is in a valid state with an unspecified
   value.
   3) Drops the current target. *this is empty after the call.
   4) Sets the target of *this to the callable f, as if by executing
   function(std::forward<F>(f)).swap(*this);. This operator does not participate in
   overload resolution unless f is Callable for argument types Args... and return type
   R.
   5) Sets the target of *this to a copy of f, as if by executing
   function(f).swap(*this);

.SH Parameters

   other - another std::function object to copy the target of
   f     - a callable to initialize the target with
.SH Type requirements
   -
   F must meet the requirements of Callable.

.SH Return value

   *this

.SH Notes

   Even before allocator support was removed from std::function in C++17, these
   assignment operators use the default allocator rather than the allocator of *this or
   the allocator of other (see LWG issue 2386).

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

      DR    Applied to              Behavior as published              Correct behavior
   LWG 2132 C++11      the overload taking a Callable object might be  constrained
                       ambiguous
   LWG 2401 C++11      assignment operator from std::nullptr_t not     required
                       required to be noexcept

.SH See also

   operator=          replaces or destroys the target
   (C++23)            \fI(public member function of std::move_only_function)\fP
   assign             assigns a new target
   (removed in C++17) \fI(public member function)\fP
